import { resultSuccess, resultError, getRequestToken, requestParams } from '../_util';
import { MockMethod } from 'vite-plugin-mock';
import { createFakeUserList } from './user';

// database
const dashboardRoute = {
  path: '/database',
  name: 'Database',
  component: 'LAYOUT',
  redirect: '/database/index',
  meta: {
    title: 'routes.webFirst.database',
    hideChildrenInMenu: true,
    icon: 'eos-icons:database',
  },
  children: [
    {
      path: 'index',
      name: 'Index',
      component: '/webFirst/database/index',
      meta: {
        hideMenu: true,
        hideBreadcrumb: true,
        title: 'routes.webFirst.database',
        currentActiveMenu: '/database',
        icon: 'eos-icons:database',
      },
    },
  ],
};

//方案生成
const schemeGenerationRoute = {
  path: '/scheme',
  name: 'Scheme',
  component: 'LAYOUT',
  redirect: '/scheme/codeFirst',
  meta: {
    icon: 'ic:outline-model-training',
    title: 'routes.webFirst.schemeGeneration',
  },
  children: [
    {
      path: 'codeFirst',
      name: 'CodeFirst',
      meta: {
        title: 'routes.webFirst.codeFirst',
        ignoreKeepAlive: true,
      },
      component: '/webFirst/scheme/codeFirst/index',
    },
    {
      path: 'dbFirst',
      name: 'DbFirst',
      meta: {
        title: 'routes.webFirst.dbFirst',
        ignoreKeepAlive: true,
      },
      component: '/webFirst/scheme/dbFirst/index',
    },

    {
      path: 'dbViewFirst',
      name: 'DbViewFirst',
      meta: {
        title: 'routes.webFirst.dbViewFirst',
        ignoreKeepAlive: true,
      },
      component: '/webFirst/scheme/dbViewFirst/index',
    },
    {
      path: 'biz',
      name: 'BIZ',
      meta: {
        title: 'routes.webFirst.biz',
        ignoreKeepAlive: true,
      },
      component: '/webFirst/scheme/biz/index',
    },
    {
      path: 'web',
      name: 'Web',
      meta: {
        title: 'routes.webFirst.web',
        ignoreKeepAlive: true,
      },
      component: '/webFirst/scheme/web/index',
    },
  ],
};
//教程
const linkRoute = {
  path: '/link',
  name: 'Link',
  component: 'LAYOUT',
  meta: {
    icon: 'ant-design:cloud-server-outlined',
    title: 'routes.webFirst.doc',
  },
  children: [
    {
      path: 'webfirst',
      name: 'WebFirst',
      meta: {
        title: 'routes.webFirst.first',
        frameSrc: 'https://www.donet5.com/Doc/11?src=webfirst',
      },
    },
    {
      path: 'sqlsugarorm',
      name: 'SqlSugarORM',
      meta: {
        title: 'routes.webFirst.sqlSugarORM',
        frameSrc: 'https://www.donet5.com/Home/Doc?src=webfirst',
      },
    },
    {
      path: 'sqlsugarioc',
      name: 'SqlSugarIOC',
      meta: {
        title: 'routes.webFirst.sqlSugarIOC',
        frameSrc: ' https://www.donet5.com/Doc/10/2250?src=webfirst',
      },
    },
    {
      path: 'admire',
      name: 'Admire',
      meta: {
        title: 'routes.webFirst.admire',
        frameSrc: 'https://www.donet5.com/Doc/28/2357?src=webfirst',
      },
    },
    {
      path: 'cooperation',
      name: 'Cooperation',
      meta: {
        title: 'routes.webFirst.cooperation',
        frameSrc: 'https://www.donet5.com/Doc/28/2358?src=webfirst',
      },
    },
  ],
};

export default [
  {
    url: '/api/getMenuList',
    timeout: 1000,
    method: 'get',
    response: (request: requestParams) => {
      const token = getRequestToken(request);
      if (!token) {
        return resultError('Invalid token!');
      }
      const checkUser = createFakeUserList().find((item) => item.token === token);
      if (!checkUser) {
        return resultError('Invalid user token!');
      }
      const id = checkUser.userId;
      let menu: Object[];
      switch (id) {
        case '1':
          dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[0].path;
          menu = [dashboardRoute, schemeGenerationRoute, linkRoute];
          break;
        case '2':
          dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[1].path;
          menu = [dashboardRoute, schemeGenerationRoute, linkRoute];
          break;
        default:
          menu = [];
      }

      return resultSuccess(menu);
    },
  },
] as MockMethod[];
